package com.teziyou.commodity.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	
	public static final String pattern1 = "yyyy-MM-dd HH:mm:ss";
	public static final String pattern2 = "yyyy-MM-dd HH:mm:ss.0";
	public static final String pattern3 = "yyyy.MM.dd";
	
	public static String formatDate(Date date, String pattern) {
		return new SimpleDateFormat(pattern).format(date);
	}
	
	public static String formatDate(String text, String pattern1, String pattern2) {
		DateFormat df1 = new SimpleDateFormat(pattern1);
		DateFormat df2 = new SimpleDateFormat(pattern2);
		try {
			return df2.format(df1.parse(text));
		} catch (ParseException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

}
